package com.affectu.forum;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import org.hibernate.validator.Length;
import org.jboss.seam.annotations.Name;

import com.affectu.common.base.EntityBase;
import com.affectu.user.User;

/**
 * Oct 7, 2008
 * 
 * @author daniel nathan
 */
@Entity
@Name("plate")
public class Plate extends EntityBase {

	private static final long serialVersionUID = -1832183983013000460L;

	@Length(max = 2048)
	private String content;

	@ManyToOne()
	@JoinColumn(name = "ownerId", referencedColumnName = "id")
	private User owner;

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "Plates_Admins", joinColumns = { @JoinColumn(name = "plateId", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "administratorId", referencedColumnName = "id") })
	private List<User> administrators;

	@OneToOne(optional = true, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "article_ID", referencedColumnName = "id", unique = true)
	private Article latestArticle;

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public List<User> getAdministrators() {
		return administrators;
	}

	public void setAdministrators(List<User> administrators) {
		this.administrators = administrators;
	}

	public Article getLatestArticle() {
		return latestArticle;
	}

	public void setLatestArticle(Article latestArticle) {
		this.latestArticle = latestArticle;
	}
}
